
#ifndef RP6DRIVINGLIGHTSNEW_H_
#define RP6DRIVINGLIGHTSNEW_H_

#include "PCF8574.h"


typedef union lightStatusUnionLeft{
	uint8_t byte;
	struct {
		unsigned BLINKER_FRONT_LEFT:1;//0
		unsigned FRONTLIGHT_LEFT:1;//1
		unsigned BLINKER_BACK_LEFT:1;//2
		unsigned BACKLIGHT_LEFT:1;//3
		unsigned unused:3;//4,5,6
		unsigned REVERSELIGHT_LEFT:1;//7
	};
} lightState_left_t;

typedef union lightStatusUnionRight{
	uint8_t byte;
	struct {
		unsigned unused1:3;//0,1,2
		unsigned REVERSELIGHT_RIGHT:1;//3
		unsigned BACKLIGHT_RIGHT:1;//4
		unsigned BLINKER_BACK_RIGHT:1;//5
		unsigned BLINKER_FRONT_RIGHT:1;//6
		unsigned FRONTLIGHT_RIGHT:1;//7
	};
} lightState_right_t;

typedef struct lights_str drivingLights_t;

struct lights_str{
	pcf8574_t *left;
	pcf8574_t *right;
	uint8_t initialized;
	void (*update)(drivingLights_t *light);
	lightState_left_t leftState;
	lightState_right_t rightState;
};

void updateDrivingLightsStatus(drivingLights_t *light){
	light->left->status.byte=light->leftState.byte;
	light->right->status.byte=light->rightState.byte;
	light->left->update(light->left);
	light->right->update(light->right);
}


void initializeDrivingLights(drivingLights_t *lig){
	lig->initialized=true;
	lig->leftState.byte=255;
	lig->rightState.byte=255;
	lig->update=&updateDrivingLightsStatus;
}


drivingLights_t *createDrivingLights(pcf8574_t *leftP, pcf8574_t *rightP){
	drivingLights_t *ret=(drivingLights_t*)malloc(sizeof(drivingLights_t));
	ret->left=leftP;
	ret->right=rightP;
	initializeDrivingLights(ret);
	return ret;
}

#endif